<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSON类型</title>
    <script>
        function f1() {
            let user = {"id": 1, "username": "admin", "password": "123456"};
            console.log(user.id);
            user.id = 2;
            console.log(user["id"])
            console.log(user["username"])
            console.log(user.password);
        }

        function f2() {
            let address = {"province": "江苏", "city": "南京"};
            let user = {"id": 1, "username": "admin", "address": address};
            let user2 = {"id": 1, "username": "admin", "address": {"province": "江苏", "city": "泰州"}};
            console.log(user.id);
            console.log(user.address.province);
            // 可以混用,但是不建议
            console.log(user2['address'].city);
        }

        function f3() {
            let users = [{
                "id": 1,
                "username": "admin",
                "password": "111111"
            }, {
                "id": 2,
                "username": "jack",
                "password": "222222"
            }, {
                "id": 3,
                "username": "tom",
                "password": "333333"
            }];
            console.log(users[0].id)
            for (let i = 0; i < users.length; i++) {
                console.log(users[i].id + "--" + users[i].username + "--" + users[i].password)
            }
        }
    </script>
</head>
<body>
<button onclick="f1()">基本语法</button>
<br>
<button onclick="f2()">对象中包含对象</button>
<br>
<button onclick="f3()">对象数组</button>
<br>
</body>
</html>